package com.zl.zsk.exception;

import com.zl.zsk.constant.RetCode;
import com.zl.zsk.pojo.vo.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author lxb
 * @version 1.0.0
 * @desc:
 * @date 2020-03-13 9:19
 */
@RestControllerAdvice
public class HandlerExceptionAdvice {
    @ExceptionHandler(Exception.class)
    public Result handleDefaultException(Exception e){
        Result result = new Result(null,RetCode.DEFAULTERROR.msg,false,RetCode.DEFAULTERROR.code);
        return result;
    }

    @ExceptionHandler(BadCredentialsException.class)
    public Result handleBadCredentialsException(){

        Result result = new Result(null,RetCode.USER_OR_PASSWORD_ERROR.msg,false,RetCode.USER_OR_PASSWORD_ERROR.code);
        return result;
    }

    @ExceptionHandler(BizException.class)
    public Result handleBizException(BizException e){
        Result retResult = new Result(null,e.message,false,e.code);
        return retResult;
    }

//    @ExceptionHandler(NotLoginException.class)
//    public Result handleNotLoginException(NotLoginException e) {
//        Result retResult = new Result(null,e.message,false,e.code);
//        return retResult;
//    }

    @ExceptionHandler(NotFoundException.class)
    public Result handleNotFountException(NotFoundException e){
        Result result = new Result(null,e.message,false,e.code);
        return result;
    }

    @ExceptionHandler({AuthDenyException.class,AccessDeniedException.class})
    public Result handleAuthDenyException(Exception e){
        Result result = new Result(null,RetCode.AUTH_DENY.msg,false,RetCode.AUTH_DENY.code);
        return result;
    }


    @ExceptionHandler(InValidParamException.class)
    public Result handleInValidParamException(InValidParamException e){
        Result retResult = new Result(null,e.message,false,e.code);
        return retResult;
    }

}
